﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AVCWizard
{
    public static class DialogTool
    {
        public const string AllFilesFilter = "Alle Dateien (*.*)|*.*";

        public static string OpenDialog(string filter, string defaultExt)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = filter;
            dlg.DefaultExt = defaultExt;
            dlg.CheckFileExists = true;
            if (dlg.ShowDialog() == true)
            {
                return dlg.FileName;
            }
            else
            {
                return String.Empty;
            }
        }

        public static string[] OpenDialogMultiSel(string filter, string defaultExt)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = filter;
            dlg.DefaultExt = defaultExt;
            dlg.CheckFileExists = true;
            dlg.Multiselect = true;
            if (dlg.ShowDialog() == true)
            {
                return dlg.FileNames;
            }
            else
            {
                return null;
            }
        }

        public static string SaveDialog(string filter, string defaultExt)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.Filter = filter;
            dlg.DefaultExt = defaultExt;
            dlg.CheckPathExists = true;
            if (dlg.ShowDialog() == true)
            {
                return dlg.FileName;
            }
            else
            {
                return String.Empty;
            }
        }

        public static string BrowseFolder(string desc)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            dlg.ShowNewFolderButton = false;
            dlg.Description = desc;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                return dlg.SelectedPath;
            }
            return null;
        }

        public static string SaveDialog(string originalFile, string filter, string defaultExt)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            if (!String.IsNullOrEmpty(originalFile))
            {
                System.IO.FileInfo finfo = new System.IO.FileInfo(originalFile);
                dlg.InitialDirectory = finfo.DirectoryName;
            }
            dlg.Filter = filter;
            dlg.DefaultExt = defaultExt;
            dlg.CheckPathExists = true;
            dlg.FileName = originalFile;
            if (dlg.ShowDialog() == true)
            {
                return dlg.FileName;
            }
            else
            {
                return String.Empty;
            }
        }
    }
}
